package com.smartthinking.destinomusical.parser;

import java.io.IOException;
import java.util.ArrayList;

import org.xml.sax.SAXException;

import android.sax.EndTextElementListener;
import android.sax.RootElement;
import android.util.Log;
import android.util.Xml;

import com.smartthinking.destinomusical.extra.Errores;

public class ParserInsert extends BaseFeedParser {
	final ArrayList<String> lista = new ArrayList<String>();
	static final String ROOT = "RESULTS";

	public ParserInsert(String feedUrl) {
		super(feedUrl);
	}

	public ArrayList<String> parse() {

		RootElement root = new RootElement(ROOT);

		root.getChild("RETURN").setEndTextElementListener(
				new EndTextElementListener() {
					public void end(String body) {
						if (!body.equals(null))
							lista.add(body);
					}
				});

		// root.setEndElementListener(new EndElementListener(){
		//
		// @Override
		// public void end() {
		// lista.add(data);
		//
		// }});

		try {
			Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8,
					root.getContentHandler());
		} catch (IOException e) {
			Errores.NO_CONNECTION = 1;
			Log.e("ParserInsert", e.getMessage());
		} catch (SAXException e) {
			Log.e("ParserInsert", e.getMessage());
		} catch (Exception e) {
			if (e.getLocalizedMessage() != null) {
				Log.e("ParserInsert", e.getLocalizedMessage());
				Errores.NO_CONNECTION = 1;
			} else
				Log.e("ParserInsert", "Unknown Exception");
		}
		return lista;
	}
}
